import BScroll from '@better-scroll/core'
import Pullup from '@better-scroll/pull-up'
import { onMounted, ref } from 'vue'
BScroll.use(Pullup)
export default function (searchMore) {
  const scrollref = ref(null)
  const scroll = ref(null)
  const ispullup = ref(true)
  onMounted(() => {
    scroll.value = new BScroll(scrollref.value, {
      pullUpLoad: true,
      observeDOM: true,
      click: true
    })
    scroll.value.on('pullingUp', async () => {
      await searchMore()
      ispullup.value = false
      scroll.value.finishPullUp()
      scroll.value.refresh()
    })
  })
  return { scrollref, ispullup }
}
